﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace grounding.parser.Parsers
{
    public enum CategoryType
    {
        Tiredness = 1,
        Stability = 2,
        Grounded = 3,
        Temperature = 4,
        //Brightness = 5,
        //LookAt = 6,
        Weight = 7,
        Motion = 8,
        Distance = 9,
        //Affection = 10
    }

    public class Category : ILogicElement
    {
        #region static

        static protected Dictionary<CategoryType, Category> categories = new Dictionary<CategoryType, Category>()
        {
            { CategoryType.Tiredness, new Category(CategoryType.Tiredness) },
            { CategoryType.Stability, new Category(CategoryType.Stability) },
            { CategoryType.Grounded, new Category(CategoryType.Grounded) },
            { CategoryType.Temperature, new Category(CategoryType.Temperature) },
            //{ CategoryType.Brightness, new Category(CategoryType.Brightness) },
            //{ CategoryType.LookAt, new Category(CategoryType.LookAt) },
            { CategoryType.Weight, new Category(CategoryType.Weight) },
            { CategoryType.Motion, new Category(CategoryType.Motion) },
            { CategoryType.Distance, new Category(CategoryType.Distance) },
            //{ CategoryType.Affection, new Category(CategoryType.Affection) }
        };

        static public Category[] Categories { get { return categories.Values.ToArray(); } }

        static public Category GetCategory(CategoryType type) { return categories[type]; }
        static public Category GetCategory(int identifier) { return categories[(CategoryType)identifier]; }
        static public Category GetCategory(string name)
        {
            CategoryType type;
            if (!Enum.TryParse<CategoryType>(name, true, out type))
                throw new ArgumentException(string.Format("String \"{0}\" could not be parsed into as a CategoryType", name));
            return categories[type];
        }

        #endregion

        public CategoryType Type { get; set; }

        public Category(CategoryType type) { Type = type; }

        public Label Positive { get { return Label.GetLabel((int)Type); } }
        public Label Negative { get { return Label.GetLabel(-((int)Type)); } }

        #region ILogicElement Members

        /// <summary>
        /// Gets the name of the category
        /// </summary>
        public string Element { get { return Type.ToString().ToLower(); } }

        public int Identifier { get { return (int)Type; } }

        #endregion

        public override string ToString() { return Element; }
    }
}
